Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make planedata public #37

Closed
wants to merge 1 commit into from
Closed

Make planedata public #37

wants to merge 1 commit into from

Conversation

Cacsjep
Copy link
Contributor

@Cacsjep Cacsjep commented Jan 23, 2024

The proposed change involves making the planeData method public, thereby allowing direct access to the underlying frame data.

This change would be bringing the possibility to create such functions like this below.

func CopyIntoRgbaImage(f astiav.Frame, dstImage *image.RGBA) {
    requiredSize := f.Linesize()[0] * f.Height()
    
    // If the existing Pix slice is smaller than needed, allocate a new slice
    if len(dstImage.Pix) < requiredSize {
        dstImage.Pix = make([]byte, requiredSize)
    }

    // Copy pixel data
    copy(dstImage.Pix, f.Data().PlaneData(0, func(linesize int) int { return linesize * f.Height() }))

    // Update stride if different
    if dstImage.Stride != f.Linesize()[0] {
        dstImage.Stride = f.Linesize()[0]
    }

    // Update rect if different
    if dstImage.Rect.Dx() != f.Width() || dstImage.Rect.Dy() != f.Height() {
        dstImage.Rect = image.Rect(0, 0, f.Width(), f.Height())
    }
}

@asticode
Copy link
Owner

Closing this PR

See #36

@asticode asticode closed this Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants